package com.czl.module_service.adapter

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.data.bean.tengyun.AssetHandleFacilityBean
import com.czl.base.data.bean.tengyun.HandleResultList
import com.czl.base.data.bean.tengyun.ReasonTypeList
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemAssetHandleApplyCardBinding
import com.czl.module_service.fragment.assetHandle.AssetHandleApplyAddFragment
import com.czl.module_service.view.ListSheetDialogFragment

class AssetHandleAddFacilityAdapter(private val fragment: AssetHandleApplyAddFragment) :
    BaseQuickAdapter<AssetHandleFacilityBean, BaseDataBindingHolder<ItemAssetHandleApplyCardBinding>>(
        R.layout.item_asset_handle_apply_card
    ) {

    var position : Int = 0

    override fun convert(
        holder: BaseDataBindingHolder<ItemAssetHandleApplyCardBinding>,
        item: AssetHandleFacilityBean,
    ) {
        item.position = holder.layoutPosition - 1
        holder.dataBinding?.run {
            item.facilityId = item.id
            item.param1 = item.id
            data = item
            adapter = this@AssetHandleAddFacilityAdapter
            executePendingBindings()
        }
        holder.dataBinding?.stvPlanAssetType?.setOnClickListener(object : View.OnClickListener{
            override fun onClick(p0: View?) {
                ListSheetDialogFragment.showBottomSheet(
                    fragment.parentFragmentManager,
                    HandleResultList
                ) {
                    item.planAssetType = it
                    item.planAssetTypeTemp = HandleResultList[it]
                    setData(holder.layoutPosition - 1,item)
                }
            }
        })
        holder.dataBinding?.stvReasonType?.setOnClickListener(object : View.OnClickListener{
            override fun onClick(p0: View?) {
                ListSheetDialogFragment.showBottomSheet(
                    fragment.parentFragmentManager,
                    ReasonTypeList
                ) {
                    item.reasonClassification = it
                    item.reasonTypeTemp = ReasonTypeList[it]
                    setData(holder.layoutPosition - 1,item)
                }
            }
        })
    }

    val delSortClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is AssetHandleFacilityBean) {
            remove(it)
            fragment.deleteSelectInfo(it.position!!,0)
        }
    })
    val onImageClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is AssetHandleFacilityBean) {
            position = it.position!!
            fragment.addChildFile()
        }
    })
}